import pandas as pd
import re
'对教练名称进行提取'

# 读取CSV文件
file_path = 'coaches_info.csv'  # 修改为实际文件路径
df = pd.read_csv(file_path)

# 定义提取主教练名字的函数
def extract_coach_name(coach_info):
    match = re.search(r'主教练是(.*?)。', str(coach_info))
    return match.group(1) if match else None

# 应用函数提取主教练名字
df['final_coach'] = df['Coach'].apply(extract_coach_name)

# 删除没有提取到主教练数据的行
df = df.dropna(subset=['final_coach'])

# 保存结果到原来的文件中
df.to_csv(file_path, index=False, encoding='utf-8-sig')

print(f"处理完成，结果已保存到 {file_path}")
